package main

import "fmt"

func lenthOfNoneRepeating(s string) int {
	lastOccured := make(map[rune]int)

	start := 0
	maxLength := 0

	for i, ch := range []rune(s) {
		if lastI, ok := lastOccured[ch]; ok && lastI >= start {
			start = lastI + 1
		}

		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}

		lastOccured[ch] = i
	}

	return maxLength
}

func main() {
	s := "Yes I love 上海" // 每个中文是三个字节 // Utf8 转成Unicode的结果

	fmt.Println(s)
	fmt.Println(len(s)) // s的字节数
	fmt.Printf("%s\n", []byte(s))
	fmt.Printf("%X\n", []byte(s))

	for _, b := range []byte(s) {
		fmt.Printf("%X ", b)
	}
	fmt.Println()

	for i, ch := range s {
		fmt.Printf("(%d %X)", i, ch)
	}

	fmt.Println()
}
